﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8" />
    <title>公文处理</title>
    <link href="../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
    <script src="../Scripts/easyUI/jquery-1.8.0.min.js" type="text/javascript"></script>
    <script src="../Scripts/QueryString.js" type="text/javascript"></script>
    <script type="text/javascript" src="../Scripts/config.js"></script>
    <script type="text/javascript" src="../Comm/Gener.js"></script>
    <script language="javascript" type="text/javascript">
        $(function () {

            var handler = new HttpHandler("BP.WF.HttpHandler.WF_WorkOpt");
            handler.AddUrlData();
            var data = handler.DoMethodReturnString("DocWord_Init");
            if (data.indexOf('err@') == 0) {
                $("#Msg").html("<br>" + data);
                return;
            }

            if (data.indexOf('url@') == 0) {

                data = data.replace('url@', '');
                data += "?FK_Flow=" + GetQueryString("FK_Flow");
                data += "&FK_Node=" + GetQueryString("FK_Node");
                data += "&WorkID=" + GetQueryString("WorkID");

                //如果返回url，就直接转向.
                SetHref(data);
                return;
            }

            //判断是否是开始节点?
            var nodeID = GetQueryString("FK_Node");
            var id = nodeID.substr(nodeID.length - 2);

            //如果是开始节点.
            if (id == '01')
                $("#resetLI").show(); //显示出来..
            else
                $("#resetLI").hide(); //隐藏掉.

            // 判断是否是是不可以编辑的状态.
            if (data.indexOf("OfficeBtnEnable=2") >= 1) {
                $("#fsUpload").hide();
                $("#Online").css("opacity", 0.2);
                $("#Online").attr("href",""); 
            }
            else {
                $("#Online").css("opacity", 1);
                $("#Online").attr("href","javascript:OpenByVSTO()"); 
            }
            $("#help").hide(); //隐藏掉.

        });

        //直接下载.
        function OpenByHttp() {
            var DocName = GetDocName();
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_WorkOpt");
            handler.AddUrlData();
            
            handler.AddPara("DocName", DocName);
            var data = handler.DoMethodReturnString("DocWord_OpenByHttp");
            if (data.indexOf('err@') == 0) {
                $("#Msg").html("<br>" + data);
                return;
            }
            window.open(data);
        }
        function GetDocName() {
            var DocName = "公文模板";
            //获取公文模板名称，默认选择上传的第一个，重新选择后用url的DocName获得模板名称
            var ens = new Entities("BP.WF.Template.DocTemplates");
            ens.Retrieve("FK_Node", GetQueryString("FK_Node"));
            if (GetQueryString("DocName") == null)
                DocName = ens[0].Name;
            else
                DocName = GetQueryString("DocName");
            return DocName;
        }
        function OpenByVSTO() {
            var DocName = GetDocName();
        
            //插件参数
            var paras = "WorkID=" + GetQueryString("WorkID") + ",";
            paras += "FK_Flow=" + GetQueryString("FK_Flow") + ",";
            paras += "TempNo=" + GetQueryString("TempNo") + ",";
            paras += "FK_Node=" + GetQueryString("FK_Node") + ",";
            
            var webUser = new WebUser();
            paras += "UserNo=" + webUser.No + ",";
            paras += "SID=" + webUser.Token + ",";
            
            //是否可以编辑(只读)
            var isEdit = "True";
            if (isEdit == "True")
                paras += "IsReadonly=0,";
            else
                paras += "IsReadonly=1,";
            
            var local = window.location.protocol + "//" + window.location.hostname + ":" + window.location.port;
            
            var urlWS = local + "/WF/CCForm/CCFormAPI.asmx?DocName="+DocName;
            var url = "httpCCWord://-fromccflow,App=WordDoc," + paras + "WSUrl=" + urlWS;
            SetHref(url);
            //window.open(url);
        }

        function Help() {
            $("#help").show(); //隐藏掉.
        }

        //上传.
        function Upload() {

            var handler = new HttpHandler("BP.WF.HttpHandler.WF_WorkOpt");
            handler.AddUrlData();
            handler.AddFormData(); //增加表单数据.
            handler.AddFileData();//增加附件数据
            var data = handler.DoMethodReturnString("DocWord_Upload");
            alert(data);
        }

        //重新生成模版.
        function ResetFile() {

            if (confirm('您确认要重新生成吗？如果打开编辑了数据，就会被冲掉。') == false)
                return;

            var handler = new HttpHandler("BP.WF.HttpHandler.WF_WorkOpt");
            handler.AddUrlData();
            var data = handler.DoMethodReturnString("DocWord_ResetFile");
            if (data.indexOf('err@') == 0) {
                alert(data);
                return;
            }

            Reload();
        }
    </script>
</head>
<body>
    <form id="cc" name="cc" action="" enctype="multipart/form-data" method="post">
        <div id="Msg"></div>

        <fieldset>
            <legend>操作</legend>
            <ul>
                <li style="padding:5px;"><a href='javascript:OpenByHttp()'><img src='../Img/FileType/doc.gif' />下载本机查看或编辑.</a></li>
                <li style="padding:5px;"><a id="Online"  href='javascript:OpenByVSTO()'><img src='../Img/FileType/xml.gif' />在线编辑</a>(需要CCWord插件) | <a href='../../DataUser/vsto/CCFlowVSTO表单插件安装程序.zip' target=blank><img src='../Img/Btn/Save.gif' />下载插件</a></li>
                <li style="padding:5px;" name="resetLI" id="resetLI"><a href='javascript:ResetFile()'><img src='../Img/redo.png' />重新生成模版</a></li>
                <li style="padding:5px;"><a href='javascript:Help()'><img src='../Img/Btn/help.gif' />帮助.</a></li>
            </ul>
        </fieldset>

        <fieldset id="fsUpload">
            <legend>上传</legend>
            <ul>
                <li>请上传本地编辑后的公文主文件.</li>
                <li>
                    <input style=" background:bottom" type="file" id="file"name="file"value="上传文件" onchange="Upload()" />
                </li>
            </ul>
            <!--<input type="button" value="上传" onclick="Upload()" />-->
        </fieldset>
        <fieldset id="help">
            <legend>下载插件-帮助</legend>
            <ul>
                <li>vsto该插件运行在Word2010以上版本.</li>

                <li> 重新生成模版:重置word模版功能. </li>
                <li> 下载到本机:就是办当前的公文（文件）下载到本机打开，如果当前节点有可以编辑的功能，就可以直接上传.</li>
                <li> 在线编辑:需要下载vsto插件，安装到本机上然后就可以直接打开,直接保存到服务器上.</li>

            </ul>
        </fieldset>


    </form>
</body>
</html>
